home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3.2 / Ham Radio Version 3.2 (Chestnut CD-ROMs)(1993).ISO / cw / morse-it / morse-it.bas next >
BASIC Source File  |  1989-06-23  |  5KB  |  136 lines

  1. 10 CLS:SCREEN 0:KEY OFF:DIM A$(40):SP=30000
  2. 20 FOR X= 1 TO 40 :READ A$(X):NEXT X
  3. 30 H$="abcdefghijklmnopqrstuvwxyz0123456789?/-."
  4. 40 CLS:PRINT"MORSE-IT! An italian `quick & dirty' Morse tutor";
  5. 50 PRINT "It transmits Morse characters in 3 ways :" : PRINT
  6. 60 PRINT "  D - keyboard-Directed":
  7. 70 PRINT "  A - rAndom strings (5 chars. long)"
  8. 80 PRINT "  F - taking input from a File" : PRINT
  9. 90 PRINT "allowing user to choose : "
  10. 100 PRINT "  speed (default 40 chars. per minute)"
  11. 110 PRINT "  oscillator tone (default 700 Hz)":PRINT
  12. 120 PRINT "and selecting output device between screen or printer "
  13. 130 PRINT "(screen by default)"
  14. 140 PRINT : PRINT "You can also `receive' Morse characters keyed-in"
  15. 150 PRINT "via the game port. See MORSE-IT.DOC for details on"
  16. 160 PRINT "how to connect the key or input device."
  17. 170 PRINT:PRINT"by IW2CNM - ALESSANDRO BRUCIAMONTI "
  18. 180 PRINT "via Roma 72 ":PRINT "27047 - S.Maria della Versa (PV)"
  19. 190 PRINT "ITALY"
  20. 200 PRINT:INPUT "rAndom, File, keyboarD, Receive [a f d r] ";K$
  21. 210 IF K$="" THEN 200
  22. 220 K$=CHR$(ASC(K$) OR 32)
  23. 230 IF K$<>"a" AND K$<>"d" AND K$<>"f" AND K$<>"r" THEN 200
  24. 240 IF K$="r" THEN 820
  25. 250 CLS:INPUT "Speed (10-130 chars./min.):";V$:V=VAL(V$):IF V=0 THEN V=40
  26. 260 IF V<10 OR V>130 THEN 250
  27. 270 INPUT "Tone (100-7000 Hz)  :";F$:F=VAL(F$):IF F=0 THEN F=700
  28. 280 IF F<100 OR F >7000 THEN 270
  29. 290 V=60/V:INPUT "Printer echo ";D$:IF D$="" THEN D$="n"
  30. 300 D$=CHR$(ASC(D$) OR 32) : IF D$<>"s" AND D$<>"n" THEN 290
  31. 310 IF D$="s" THEN OPEN "prn" FOR OUTPUT AS #1:PR=-1
  32. 320 IF K$<>"a" THEN 530
  33. 330 REM
  34. 340 REM 23 Lines of 13 Strings of 5 Characters are to be transmitted
  35. 350 REM
  36. 360 CLS:FOR L=1 TO 23:FOR S=1 TO 13:FOR C=1 TO 5
  37. 370 RANDOMIZE(TIMER):X=INT(RND(TIMER)*39+1)
  38. 380 IF X>40 OR X<1 THEN 370
  39. 390 C$=MID$(H$,X,1):PRINT C$;:IF PR THEN PRINT#1,C$;
  40. 400 GOSUB 460:NEXT C
  41. 410 PRINT " ";:SOUND SP,V*7:IF PR THEN PRINT#1," ";
  42. 420 NEXT S:PRINT CHR$(13);:IF PR THEN PRINT#1,CHR$(13)+CHR$(10)
  43. 430 NEXT L:PRINT"Press a key to continue...ESC to exit."
  44. 440 O$=INKEY$:IF O$="" THEN 440 ELSE IF O$<>CHR$(27) THEN 360
  45. 450 CLOSE 1:END
  46. 460 SOUND SP,V*5:FOR M=1 TO LEN(A$(X)):Z$=MID$(A$(X),M,1)
  47. 470 IF Z$="1" THEN SOUND F,V*3
  48. 480 IF Z$="0" THEN SOUND F,V
  49. 490 SOUND SP,V:NEXT M:RETURN
  50. 500 DATA 01,1000,1010,100,0,0010,110,0000,00,0111,101,0100,11,10,111,0110,1101
  51. 510 DATA 010,000,1,001,0001,011,1001,1011,1100,11111,01111,00111,00011,00001
  52. 520 DATA 00000,10000,11000,11100,11110,001100,10010,10001,000000
  53. 530 IF K$<>"f" THEN 660
  54. 540 CLS: PRINT "File input section ":PRINT:PRINT
  55. 550 INPUT "name of file to open (12 chars. max) "; NF$
  56. 560 NF$=LEFT$(NF$,12)
  57. 570 ON ERROR GOTO 550
  58. 580 OPEN NF$ FOR INPUT AS #2
  59. 590 ON ERROR GOTO 1330
  60. 600 WHILE NOT EOF(2)
  61. 610 C$=INPUT$(1,#2)
  62. 620 GOSUB 720
  63. 630 REM
  64. 640 WEND :CLOSE #2
  65. 650 GOTO 540
  66. 660 CLS: PRINT "Keyboard-directed input section :"
  67. 670 PRINT "input lines with <ENTER> key "
  68. 680 PRINT "an `*' as first character of the line ends program "
  69. 690 PRINT:INPUT Y$:IF Y$="*" THEN END
  70. 700 FOR II=1 TO LEN(Y$) : C$=MID$(Y$,II,1)
  71. 710 GOSUB 720 :NEXT II:PRINT:GOTO 690
  72. 720 REM this routine discards non-Morse characters
  73. 730 PRINT C$; :IF PR THEN PRINT #1,C$;
  74. 740 C=(ASC(C$) AND 127 OR 32):IF C<45 THEN RETURN
  75. 750 IF C=32 THEN SOUND SP,7*V:RETURN
  76. 760 C$=CHR$(C) : FOR X=1 TO 40
  77. 770 IF MID$(H$,X,1)=C$ THEN 790
  78. 780 NEXT X: IF X >40 THEN SOUND SP,7*V:GOTO 800
  79. 790 GOSUB 460
  80. 800 RETURN
  81. 810 END
  82. 820 E$="":C=0:P=0
  83. 830 CLS:PRINT "MORSE-IT : receiver section "
  84. 840 DEF SEG=0
  85. 850 PORTA=&H201
  86. 860 REM game port address
  87. 870 REM on my PC clone :
  88. 880 REM a value of 176 on game port indicates "close key condition"
  89. 890 REM a value of 240 indicates "open key condition"
  90. 900 REM check these values on YOUR PC if MORSE-IT seems not to work!
  91. 910 I=INP(PORTA)
  92. 920 REM inputs a value from the game port
  93. 930 IF I=240 THEN P=P+1:GOTO 910
  94. 940 REM P computes the time of "key open" condition during
  95. 950 REM character parsing :
  96. 960 REM change the values of P if your computer is faster or
  97. 970 REM slower (!!!) than a 4.77 MHz standard PC.
  98. 980 REM increase P values if faster, decrease if slower
  99. 990 REM
  100. 1000 IF P>150 THEN GOSUB 1220:GOSUB 1260:E$="":C=0 :GOTO 1100
  101. 1010 REM
  102. 1020 REM key open condition for a "P" (pause) value > 150 means that
  103. 1030 REM a character has been parsed
  104. 1040 REM
  105. 1050 IF P>30 THEN GOSUB 1220: C=0
  106. 1060 REM
  107. 1070 REM key off condition for a "P" value greater than 30 means that
  108. 1080 REM a character element (dot or line) has been parsed
  109. 1090 REM
  110. 1100 P=0:IF I=176 THEN C=C+1:GOTO 910
  111. 1110 REM
  112. 1120 GOTO 910
  113. 1130 END
  114. 1140 REM C computes the "key closed" duration :
  115. 1150 REM change the values of C if your computer is faster or slower
  116. 1160 REM than a standard P.C. (4.77 MHz clock)
  117. 1170 REM increase if faster, decrease if slower...
  118. 1180 REM
  119. 1190 REM C > 40 means that a "line" has been detected
  120. 1200 REM C<= 40 indicate that a "dot" has been detected
  121. 1210 REM
  122. 1220 IF C<=40  THEN E$=E$+"0"
  123. 1230 IF C> 40 THEN E$=E$+"1"
  124. 1240 C=0
  125. 1250 RETURN
  126. 1260 REM
  127. 1270 FLAG=0:FOR I=1 TO 40
  128. 1280 IF E$=A$(I) THEN PRINT MID$(H$,I,1);:FLAG=I
  129. 1290 NEXT:IF FLAG=0 THEN PRINT "*";
  130. 1300 C=0:E$="":IF P>700 THEN  PRINT " ";
  131. 1310 REM
  132. 1320 FLAG=0:RETURN
  133. 1330 CLS: PRINT "Morse-it detected an error... check your hardware"
  134. 1340 PRINT "and re-run program."
  135. 1350 FOR I=1 TO 10000 : NEXT I:SYSTEM
  136.